/**
 * @author rxliuli
 */
class QueryEntity {
    constructor({
                    deviceName = '',
                    deviceNameAction = 0,
                    houseId = '',
                    appState = '',
                } = {}) {
        this.deviceName = deviceName;
        this.deviceNameAction = deviceNameAction;
        this.houseId = houseId;
        this.appState = appState;
    }
}
const app = new BasicTableVue({
    data() {
        return {
            api: baseMonitorDeviceApi,
            columns: [
                new TableColumn({width: 30, type: 'selection'}),
                new TableColumn({
                    prop: 'deviceType',
                    title: '设备类型',
                    formatter: ({deviceType}) => deviceType || '监测设备',
                }),
                new TableColumn({prop: 'deviceName', title: '设备号'}),
                new TableColumn({prop: 'hostName', title: '设备IP或主机名'}),
                new TableColumn({prop: 'ctrPort', title: '设备端口'}),
                new TableColumn({
                    prop: 'houseId',
                    title: '所在机房',
                    formatter: ({houseId}) => this.houseMap.get(houseId),
                }),
                new TableColumn({prop: 'syncState', title: '同步状态'}),
                new TableColumn({
                    prop: 'appStatus',
                    title: '应用状态',
                    formatter: ({serverInfo: {appStatus = -1} = {}} = {}) => fieldFormatter.generator(fieldFormatter.baseMonitorDevice.appStateMap)(parseInt(appStatus)),
                }),
                new TableColumn({prop: 'operating', title: '操作', customComponent: true}),
            ],
            houseMap: new Map(),
        }
    },
    methods: {
        createForm() {
            return new QueryEntity({
                houseId: forward.getData().id
            })
        },
        async downloadTemplate() {
            await baseMonitorDeviceApi.downloadTemplate('监控设备信息管理导入模板.xlsx')
        },
        changeUpdateTime([start, end]) {
            this.form.updateTimeStart = start
            this.form.updateTimeEnd = end
        },
        update({row}) {
            forward('/basic-data/modify/admin_monitor_device_modify', row)
        },
        close({row}) {

        },
        async deleteById({row}) {
            if (await ajaxOption({
                res: this.api.delete(row.id),
                danger: '删除监控设备失败',
                success: '删除监控设备成功',
            })) {
                await this.searchPage()
            }
        },
        async init() {
            this.houseMap = rx.arrayToMap(await baseHouseInfoApi.selectList(), 'id', 'houseName')
        },
    },
    computed: {
        fieldFormatter() {
            return fieldFormatter
        },
    },
})
